import collections
class Solution(object):
    def maxRepOpt1(self, text):
        d = collections.Counter(text)
        max_len = 0
        for key in d:
            now_max = 0
            last0 = 0
            last1 = 0
            for c in text:
                if c == key:
                    last0 += 1
                    last1 += 1
                else:
                    last1 = last0 + 1
                    last0 = 0
                now_max = max(now_max, last0, last1)
            max_len = max(max_len, min(now_max, d[key]))
        return max_len
